<template>
  <yk-space dir="vertical" size="xl" class="data-charts">
    <!-- 访问量卡片 -->
    <div class="chart-card">
      <div class="chart-card__header">
        <h3 class="chart-card__title">访问量</h3>
        <yk-radio-group v-model="visitRadio" type="button" :solid="true" @change="getVisit" class="chart-card__filters">
          <yk-radio value="week">近一周</yk-radio>
          <yk-radio value="moon">近一月</yk-radio>
        </yk-radio-group>
      </div>
      <div class="chart-card__body">
        <line-chart :data="visitData" chart-height="208px"></line-chart>
      </div>
    </div>

    <!-- 数据监测卡片 -->
    <div class="chart-card">
      <div class="chart-card__header">
        <h3 class="chart-card__title">数据监测</h3>
        <yk-radio-group v-model="checkRadio" type="button" :solid="true" @change="getVisit" class="chart-card__filters">
          <yk-radio value="week">近一周</yk-radio>
          <yk-radio value="moon">近一月</yk-radio>
        </yk-radio-group>
      </div>
      <div class="chart-card__body chart-card__body--flex">
        <div class="pie-chart-container">
          <pie-chart title="设备总数" :data="survey.data.device" chart-height="208px"></pie-chart>
        </div>
        <div class="pie-chart-container">
          <pie-chart title="访问总数" :data="survey.data.website" chart-height="208px"></pie-chart>
        </div>
      </div>
    </div>
  </yk-space>
</template>

<script setup lang="ts">
import { ref, onMounted } from 'vue'
import { LineChart, PieChart } from '../echarts';
import { visit, survey } from '@/mock/data';

const visitData = ref([])

const getVisit = (e: string) => {
  let data = visit.data
  if (e === 'week') {
    data = data.slice(0, 7)
  }
  visitData.value = data
}

const visitRadio = ref('week')
const checkRadio = ref('week')

onMounted(() => {
  getVisit(visitRadio.value)
})
</script>

<style lang="less" scoped>
// 色彩变量
@card-bg: #ffffff;
@card-radius: 16px;
@card-shadow: 0 8px 30px rgba(0, 0, 0, 0.05);
@card-hover-shadow: 0 15px 35px rgba(0, 0, 0, 0.08);
@title-color: #2c3e50;
@border-color: #edf1f7;
@accent-color: #3a7bd5;
@accent-gradient: linear-gradient(135deg, #3a7bd5, #56ccf2);
@transition-time: 0.4s;
@transition-easing: cubic-bezier(0.16, 1, 0.3, 1);

// 容器样式
.data-charts {
  width: 100%;
  max-width: 1200px;
  margin: 0 auto;
}

// 图表卡片基础样式
.chart-card {
  background: @card-bg;
  border-radius: @card-radius;
  box-shadow: @card-shadow;
  padding: 28px;
  transition: all @transition-time @transition-easing;
  border: 1px solid rgba(237, 241, 247, 0.6);
  width: 100%;
  position: relative;
  overflow: hidden;

  &::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 3px;
    background: @accent-gradient;
    opacity: 0;
    transition: opacity @transition-time @transition-easing;
  }

  &:hover {
    box-shadow: @card-hover-shadow;
    transform: translateY(-3px);

    &::before {
      opacity: 1;
    }
  }

  // 卡片头部
  &__header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 24px;
    padding-bottom: 18px;
    position: relative;

    &::after {
      content: '';
      position: absolute;
      bottom: 0;
      left: 0;
      right: 0;
      height: 1px;
      background: linear-gradient(to right,
          @border-color 0%,
          @border-color 70%,
          transparent 100%);
    }
  }

  // 卡片标题
  &__title {
    font-size: 17px;
    font-weight: 600;
    color: @title-color;
    margin: 0;
    position: relative;
    padding-left: 14px;
    letter-spacing: 0.3px;

    &::before {
      content: '';
      position: absolute;
      left: 0;
      top: 50%;
      transform: translateY(-50%);
      height: 18px;
      width: 4px;
      background: @accent-gradient;
      border-radius: 2px;
      box-shadow: 0 2px 8px rgba(58, 123, 213, 0.3);
    }
  }

  // 筛选按钮组
  &__filters {
    :deep(.yk-radio-group) {
      border: 1px solid @border-color;
      border-radius: 20px;
      overflow: hidden;
      box-shadow: 0 2px 8px rgba(0, 0, 0, 0.03);
    }

    :deep(.yk-radio-button) {
      border-radius: 16px;
      font-size: 13px;
      padding: 0 16px;
      height: 32px;
      line-height: 32px;
      border: none;
      position: relative;
      transition: all 0.25s;

      &.is-active {
        background: @accent-gradient;
        color: white;
        font-weight: 500;
        box-shadow: 0 3px 8px rgba(58, 123, 213, 0.25);

        &::before {
          opacity: 0;
        }
      }

      &:not(.is-active):hover {
        color: @accent-color;
        background-color: rgba(58, 123, 213, 0.05);
      }
    }
  }

  // 卡片内容区域
  &__body {
    position: relative;
    padding: 10px 0;

    &--flex {
      display: flex;
      gap: 36px;
    }
  }
}

// 饼图容器
.pie-chart-container {
  flex: 1;
  min-width: 0;
  position: relative;

  &::after {
    content: '';
    position: absolute;
    top: 10%;
    bottom: 10%;
    width: 1px;
    right: -18px;
    background: linear-gradient(to bottom, transparent, @border-color, transparent);
    display: block;
    opacity: 0.6;
  }

  &:last-child::after {
    display: none;
  }
}

// 响应式布局
@media (max-width: 1100px) {
  .chart-card {
    padding: 24px;
  }
}

@media (max-width: 992px) {
  .data-charts {
    max-width: 100%;
  }

  .pie-chart-container::after {
    right: -16px;
  }
}

@media (max-width: 768px) {
  .chart-card {
    padding: 20px;
    border-radius: 14px;

    &__header {
      flex-direction: column;
      align-items: flex-start;
      gap: 14px;
      padding-bottom: 16px;
      margin-bottom: 20px;
    }

    &__filters {
      width: 100%;
      display: flex;
      justify-content: flex-end;

      :deep(.yk-radio-button) {
        padding: 0 14px;
        font-size: 12px;
        height: 30px;
        line-height: 30px;
      }
    }

    &__body--flex {
      flex-direction: column;
      gap: 32px;
    }

    .pie-chart-container::after {
      width: 0; // 垂直排列时移除分隔线
    }

    &:hover {
      transform: translateY(-2px);
    }
  }
}

@media (max-width: 576px) {
  .chart-card {
    padding: 16px;
    border-radius: 12px;
    margin-bottom: 16px;

    &::before {
      height: 2px;
    }

    &__title {
      font-size: 15px;
      padding-left: 12px;

      &::before {
        width: 3px;
        height: 16px;
      }
    }

    &__header {
      margin-bottom: 16px;
      padding-bottom: 14px;
    }

    &__filters {
      :deep(.yk-radio-button) {
        padding: 0 12px;
        height: 28px;
        line-height: 28px;
      }
    }
  }
}

@media (max-width: 480px) {
  .chart-card {
    &__filters {
      :deep(.yk-radio-button) {
        padding: 0 10px;
        font-size: 12px;
      }
    }

    &__title {
      font-size: 14px;
    }

    &__body--flex {
      gap: 24px;
    }
  }
}

@media (max-width: 380px) {
  .chart-card {
    padding: 14px 12px;

    &__header {
      gap: 12px;
    }

    &__filters {
      :deep(.yk-radio-button) {
        padding: 0 8px;
      }
    }
  }
}
</style>
